//
//  VisitorViewController.m
//  我的微博
//
//  Created by tom-1 on 15/12/6.
//  Copyright © 2015年 tom-1. All rights reserved.
//

#import "VisitorViewController.h"
#import "OAuthViewController.h"
#import "UserAccountViewModel.h"


@interface VisitorViewController () <VisitorViewDelegate>

@end

@implementation VisitorViewController



- (void)viewDidLoad {
    [super viewDidLoad];
    self.visitorView.delegate = self;
    
}

- (void)loadView {
    // 根据用户登录情况来显示哪个根视图
    UserAccountViewModel *vm = [[UserAccountViewModel alloc] init];
    self.userlogin = vm.userlogin;
    
    self.userlogin ?[super loadView] : [self setupVisitorView];
    
}

// 设置访客视图
- (void)setupVisitorView {
    // 替换根视图
    self.visitorView = [[VisitorView alloc] init];
    self.view = self.visitorView;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"注册" style:UIBarButtonItemStylePlain target:self action:@selector(visitorViewDidRegister)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"登录" style:UIBarButtonItemStylePlain target:self action:@selector(visitorVIewDidLogin)];
    
}

// VisitorViewDelegate代理方法
- (void)visitorViewDidRegister {
    NSLog(@"注册");

}

- (void)visitorVIewDidLogin {
    OAuthViewController *vc = [[OAuthViewController alloc] init];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
    [self presentViewController:nav animated:YES completion:nil];
}


@end
